package com.peng.community.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

//@Component
@Aspect
public class AlphaAspect {

    //service包下任何类型返回值和参数的业务方法
    @Pointcut("execution(* com.peng.community.service.*.*(..))")
    public void pointCut() {

    }

    @Before("pointCut()")
    public void beforeService() {
        System.out.println("业务方法即将执行");
    }

    @After("pointCut()")
    public void afterService() {
        System.out.println("业务方法返回之前");
    }

    @AfterReturning("pointCut()")
    public void afterServiceReturning() {
        System.out.println("业务方法返回辣");
    }

    @AfterThrowing("pointCut()")
    public void afterServiceThrowing() {
        System.out.println("业务方法很不幸抛出了异常");
    }

    @Around("pointCut()")
    public Object aroundService(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("3D环绕通知开始");
        //方法执行
        Object result = proceedingJoinPoint.proceed();

        System.out.println("4D环绕通知Over");
        return result;
    }

}
